package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.FieldType;
import ru.aslanov.schedule.client.ScheduleUser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * Created: Jan 29, 2010 6:59:02 PM
 *
 * @author Sergey Aslanov
 */
public class LocationsDS extends ChildDS {
    private static Map<String, DataSource> instances = new HashMap<String, DataSource>();

    public static DataSource getInstance(ScheduleUser scheduleUser) {
        DataSource dataSource = instances.get(scheduleUser.getScheduleKey());
        if (dataSource == null) {
            dataSource = new LocationsDS(scheduleUser.getScheduleKey(), scheduleUser);
            instances.put(scheduleUser.getScheduleKey(), dataSource);
        }
        return dataSource;
    }

    private LocationsDS(String scheduleKey, InputLangProvider inputLangProvider) {
        super("Location", scheduleKey, "schedule", inputLangProvider);

        DataSourceField locId = new DataSourceField("id", FieldType.TEXT, cnt.idField());
        //locId.setPrimaryKey(true);
        //locId.setRequired(true);
        locId.setHidden(true);

        DataSourceField name = new DataSourceField("name", FieldType.TEXT, cnt.nameField());
        name.setRequired(true);

        DataSourceField address = new DataSourceField("address", FieldType.TEXT, cnt.addressField());
        name.setRequired(true);

        DataSourceField metro = new DataSourceField("metro", FieldType.TEXT, cnt.metroField());

        DataSourceTextField comment = new DataSourceTextField("comments", cnt.descriptionField(), 2000);
        //comment.setValueXPath("comments");

        setFields(encodedKey, /*scheduleKey,*/ locId, name, address, metro, comment);

    }


}
